package com.jiaoyou.baojian.wiget;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jiaoyou.baojian.R;

/**
 * Created by DemonZYM on 17/5/8.
 */

public class CustomToast {
    public static void showToast(Context context, String message) {
        View toastRoot = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
        TextView textView = (TextView) toastRoot.findViewById(R.id.msg);
        RelativeLayout content = (RelativeLayout) toastRoot.findViewById(R.id.content);
        textView.setText(message);
        Toast toastStart = new Toast(context);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        LinearLayout.LayoutParams layoutParams =
                new LinearLayout.LayoutParams(outMetrics.widthPixels, outMetrics.heightPixels);
        content.setLayoutParams(layoutParams);
        toastStart.setMargin(0, 0);
        toastStart.setGravity(Gravity.TOP, 0, 0);
        toastStart.setDuration(Toast.LENGTH_SHORT);
        toastStart.setView(toastRoot);
        toastStart.show();
    }
}
